package org.awa.demo.opencv.task.kunming;

import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.Point;

public class OutSideLineInterpolation implements IInterpolation {
    @Override
    public ValueBean interpolate(Point point, Geometry source, double value) {
        try{
            double distance = source.distance(point);
            if(distance > 2000){
                return null;
            }
            double leqt = cal(distance, value);
            return new ValueBean(leqt, distance);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    private double cal(double distance,double value) throws Exception{
        if (distance < 1) {
            return value;
        }
        //因为计算认为为无限长线声源本身的声音。而衰减公式是两个距离之间的比值(r / r0)，故假设r0为0.01米，即1cm的距离
        return value - 10d * Math.log10(distance * 10);
    }
}
